<template>
	<view class="page page-fill">
		<view class="page-block info-list">
			<view class="info-wapper info-line-upbottom" data-mtype="avatar" @click="gotoModify">
				<view class="info-lbl">头像</view>
				<view class="right-wapper">
					<image class="info-avatar" :src="userInfo.avatar" mode=""></image>
					<view class="info-next">
						<image class="next-next" src="https://img0.baidu.com/it/u=919935281,4291544585&fm=26&fmt=auto&gp=0.jpg" mode=""></image>
					</view>
				</view>
			</view>
			
			<view>
				<view class="line"></view>
			</view>
			
			<view class="info-wapper" data-mtype="username" @click="gotoModify">
				<view class="info-lbl">昵称</view>
				<view class="right-wapper">
					<view class="info-text">{{userInfo.username}}</view>
					<view class="info-next">
						<image class="next-next" src="https://img0.baidu.com/it/u=919935281,4291544585&fm=26&fmt=auto&gp=0.jpg" mode=""></image>
					</view>
				</view>
			</view>
			
			<view>
				<view class="line"></view>
			</view>
			
			<view class="info-wapper" data-mtype="birthday" @click="gotoModify">
				<view class="info-lbl">生日</view>
				<view class="right-wapper">
					<view class="info-text">{{userInfo.birthday}}</view>
					<view class="info-next">
						<image class="next-next" src="https://img0.baidu.com/it/u=919935281,4291544585&fm=26&fmt=auto&gp=0.jpg" mode=""></image>
					</view>
				</view>
			</view>
			
			<view>
				<view class="line"></view>
			</view>
			
			<view class="info-wapper" data-mtype="sex" @click="gotoModify">
				<view class="info-lbl">性别</view>
				<view class="right-wapper">
					<view class="info-text">{{userInfo.sex==0?"男":"女"}}</view>
					<view class="info-next">
						<image class="next-next" src="https://img0.baidu.com/it/u=919935281,4291544585&fm=26&fmt=auto&gp=0.jpg" mode=""></image>
					</view>
				</view>
			</view>
		
		</view> 
		
		<view class="info-footer">
			<view class="info-clear">
				<button @click="clearStorage" type="default">清除缓存</button> 
			</view>
			<view class="info-clear info-logout">
				<button @click="logout" type="warn">退出登录</button> 
			</view>
		</view>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo : {}
			}
		},
		onShow() {
			var user = uni.getStorageSync('gUser');
			if(user) {
				this.userInfo = user;
			}else {
				uni.showToast({
					title: "请先进行登录，谢谢~",
					mask: false,
					duration: 800
				})
				uni.switchTab({
					url:"../me/me"
				})
			}
		},
		methods: {
			clearStorage(){
				// uni.removeStorage('gUser');
				uni.clearStorageSync();
				uni.showToast({
					title: "清除缓存成功~",
					mask: false,
					duration: 800
				})
				
				uni.switchTab({
					url:"../me"
				})
			},
			logout(){
				uni.clearStorageSync();
				uni.showToast({
					title: "退出登录成功~",
					mask: false,
					duration: 800
				})
				
				uni.switchTab({
					url:"../me"
				})
			},
			gotoModify(e){
				console.log(e)
				uni.navigateTo({
					url:"../meModify/meModify?mtype=" + e.currentTarget.dataset.mtype
				})
			}
		}
	}
</script>

<style>
@import url("meInfo.css");
</style>
